Look for previous used application name for config folder.
authorCamila Ayres <hello@camilasan.com>
Mon, 20 Jan 2025 14:00:43 +0000 (15:00 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 11 Feb 2025 09:57:01 +0000 (10:57 +0100)
oldDir => legacyDataDir.

Signed-off-by: Camila Ayres <hello@camilasan.com>
src/gui/application.cpp

index 10bf7cfaa736c07dcde64ddc5aa0883cd13d3d98..641f32c749cf6eda8261cced59f6bdc9bd7e27e4 100644 (file)
@@ -240,14 +240,14 @@ Application::Application(int &argc, char **argv)
     setWindowIcon(_theme->applicationIcon());
 
     if (!ConfigFile().exists()) {
-        // Migrate from version <= 2.4
         setApplicationName(_theme->appNameGUI());
-        // We need to use the deprecated QDesktopServices::storageLocation because of its Qt4
-        // behavior of adding "data" to the path
-        QString oldDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/data/" + organizationName() + "/" + applicationName();
-        if (oldDir.endsWith('/')) oldDir.chop(1); // macOS 10.11.x does not like trailing slash for rename/move.
+        QString legacyDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + APPLICATION_CONFIG_NAME;
+
+        if (legacyDir.endsWith('/')) {
+            legacyDir.chop(1); // macOS 10.11.x does not like trailing slash for rename/move.
+        }
         setApplicationName(_theme->appName());
-        if (QFileInfo(oldDir).isDir()) {
+        if (QFileInfo(legacyDir).isDir()) {
             auto confDir = ConfigFile().configPath();
 
             // macOS 10.11.x does not like trailing slash for rename/move.
@@ -255,17 +255,17 @@ Application::Application(int &argc, char **argv)
                 confDir.chop(1);
             }
 
-            qCInfo(lcApplication) << "Migrating old config from" << oldDir << "to" << confDir;
+            qCInfo(lcApplication) << "Migrating old config from" << legacyDir << "to" << confDir;
 
-            if (!QFile::rename(oldDir, confDir)) {
-                qCWarning(lcApplication) << "Failed to move the old config directory to its new location (" << oldDir << "to" << confDir << ")";
+            if (!QFile::rename(legacyDir, confDir)) {
+                qCWarning(lcApplication) << "Failed to move the old config directory to its new location (" << legacyDir << "to" << confDir << ")";
 
                 // Try to move the files one by one
                 if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {
-                    const QStringList filesList = QDir(oldDir).entryList(QDir::Files);
+                    const QStringList filesList = QDir(legacyDir).entryList(QDir::Files);
                     qCInfo(lcApplication) << "Will move the individual files" << filesList;
                     for (const auto &name : filesList) {
-                        if (!QFile::rename(oldDir + "/" + name,  confDir + "/" + name)) {
+                        if (!QFile::rename(legacyDir + "/" + name,  confDir + "/" + name)) {
                             qCWarning(lcApplication) << "Fallback move of " << name << "also failed";
                         }
                     }
@@ -273,7 +273,7 @@ Application::Application(int &argc, char **argv)
             } else {
 #ifndef Q_OS_WIN
                 // Create a symbolic link so a downgrade of the client would still find the config.
-                QFile::link(confDir, oldDir);
+                QFile::link(confDir, legacyDir);
 #endif
             }
         }